package com.yb0os1.Array;

public class SortedSquares {
    public int[] sortedSquares(int[] nums) {
        int[] newNums = new int[nums.length];
        int l = 0, r = nums.length - 1;
        while (l<=r){
            if (Math.abs(nums[l])>Math.abs(nums[r])){
                newNums[r-l]=nums[l]*nums[l];
                l++;
            }else {
                newNums[r-l]=nums[r]*nums[r];
                r--;
            }
        }
        return newNums;
    }
}
